package com.sky.web.app;

import com.sky.dto.CategoryDTO;
import com.sky.dto.SetmealPageDTO;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/setmeal")
public class AppSetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    @GetMapping("/list")
    public Result findList(Long categoryId){ //1 接收参数

        //2 封装到 DTO
        SetmealPageDTO setmealPageDTO = new SetmealPageDTO();
        setmealPageDTO.setCategoryId(categoryId);
        setmealPageDTO.setStatus(1);
        //2 封装到 DTO
        /*SetmealPageDTO dto = SetmealPageDTO
                .builder()
                .categoryId(categoryId)
                .build();*/ //为什么不能用 todo
        //3 调用Service
        List<SetmealVO> list = setmealService.findList(setmealPageDTO);
        //4 返回结果
        return Result.success(list);

    }

    /**
     * 根据套餐id查询菜品选项
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    public Result findDishBySetmealId(@PathVariable("id") Long id){
        //1 接收参数
        //2 调用Service
        List<DishItemVO> dishItemVOList = setmealService.findDishBySetmealId(id);
        //3 返回结果
        return Result.success(dishItemVOList);
    }
}
